package com.yuexi.app.table;

import com.yuexi.app.coverter.Converter;
import com.yuexi.domain.syscode.SysCodeDomain;
import com.yuexi.domain.syscode.bo.SysCodeResultBO;
import com.yuexi.domain.table.TableDomain;
import com.yuexi.domain.table.bo.TableBO;
import com.yuexi.table.api.TableService;
import com.yuexi.table.dto.TableDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jie
 * @date 2023/4/5 -15:49
 */
@Service
public class TableServiceImpl implements TableService {

    @Autowired
    private TableDomain domain;
    @Autowired
    private SysCodeDomain sysCodeDomain;

    @Override
    public Map<String, List<TableDTO>> list() {
        Map<String, List<TableDTO>> result = new LinkedHashMap<>();

        // 获取所有区域类型
        List<SysCodeResultBO> areaTypeList = sysCodeDomain.list("AREA_TYPE");

        // 初始化
        for (SysCodeResultBO sysCodeResultBO : areaTypeList) {
            result.put(sysCodeResultBO.getSubCode(), new ArrayList<>());
        }

        // 获取所有桌台
        List<TableBO> tableBOList = domain.getAll();
        for (TableBO tableBO : tableBOList) {
            result.get(tableBO.getAreaType()).add(Converter.INSTANCE.toTableDTO(tableBO));
        }

        return result;
    }
}
